<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     enterprise_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<div class="box-title">
    <h2><?php echo $this->__('Write Your Own Review') ?></h2>
</div>
<?php if ($this->getAllowWriteReviewFlag()): ?>
<form action="<?php echo $this->getAction() ?>" method="post" id="review-form">
    <?php echo $this->getBlockHtml('formkey'); ?>
    <?php echo $this->getChildHtml('form_fields_before')?>
    <div class="box-content">
        <h3 class="product-name"><?php echo $this->__("You're reviewing:"); ?> <span><?php echo $this->escapeHtml($this->getProductInfo()->getName()) ?></span></h3>
        <?php if ($this->getRatings() && $this->getRatings()->getSize()): ?>
            <span id="input-message-box"></span>
            <ul class="form-list">
                <li>
                    <label class="required"><em>*</em><?php echo $this->__('How do you rate this product?') ?></label>
                    <div class="input-box">
                        <table class="data-table review-summary-table" id="product-review-table">
                            <col />
                            <col width="1" />
                            <col width="1" />
                            <col width="1" />
                            <col width="1" />
                            <col width="1" />
                            <thead>
                                <tr>
                                    <th>&nbsp;</th>
                                    <th><div class="rating-box"><span class="rating nobr" style="width:20%" title="<?php echo Mage::helper('core')->quoteEscape($this->__('1 star')) ?>"><?php echo $this->__('1 star') ?></span></div></th>
                                    <th><div class="rating-box"><span class="rating nobr" style="width:40%" title="<?php echo Mage::helper('core')->quoteEscape($this->__('2 stars')) ?>"><?php echo $this->__('2 stars') ?></span></div></th>
                                    <th><div class="rating-box"><span class="rating nobr" style="width:60%" title="<?php echo Mage::helper('core')->quoteEscape($this->__('3 stars')) ?>"><?php echo $this->__('3 stars') ?></span></div></th>
                                    <th><div class="rating-box"><span class="rating nobr" style="width:80%" title="<?php echo Mage::helper('core')->quoteEscape($this->__('4 stars')) ?>"><?php echo $this->__('4 stars') ?></span></div></th>
                                    <th><div class="rating-box"><span class="rating nobr" style="width:100%" title="<?php echo Mage::helper('core')->quoteEscape($this->__('5 stars')) ?>"><?php echo $this->__('5 stars') ?></span></div></th>
                                </tr>
                            </thead>
                            <tbody>
                            <?php foreach ($this->getRatings() as $_rating): ?>
                                <tr>
                                    <td class="label"><?php echo $this->escapeHtml($_rating->getRatingCode()) ?></td>
                                <?php foreach ($_rating->getOptions() as $_option): ?>
                                    <td class="value"><input type="radio" name="ratings[<?php echo $_rating->getId() ?>]" id="<?php echo $this->escapeHtml($_rating->getRatingCode()) ?>_<?php echo $_option->getValue() ?>" value="<?php echo $_option->getId() ?>" class="radio" /></td>
                                <?php endforeach; ?>
                                </tr>
                            <?php endforeach; ?>
                            </tbody>
                        </table>
                        <input type="hidden" name="validate_rating" class="validate-rating" value="" />
                        <script type="text/javascript">decorateTable('product-review-table')</script>
                    </div>
                </li>
            </ul>
        <?php endif ?>
        <ul class="form-list">
            <li>
                <label for="nickname_field" class="required"><em>*</em><?php echo $this->__('Nickname') ?></label>
                <div class="input-box"><input type="text" name="nickname" id="nickname_field" class="input-text required-entry" value="<?php echo $this->escapeHtml($data->getNickname()) ?>" /></div>
            </li>
            <li>
                <label for="summary_field" class="required"><em>*</em><?php echo $this->__('Summary of Your Review') ?></label>
                <div class="input-box"><input type="text" name="title" id="summary_field" class="input-text required-entry" value="<?php echo $this->escapeHtml($data->getTitle()) ?>" /></div>
            </li>
            <li>
                <label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
                <div class="input-box"><textarea name="detail" id="review_field" cols="5" rows="3" class="required-entry"><?php echo $this->escapeHtml($data->getDetail()) ?></textarea></div>
            </li>
        </ul>
        <div class="buttons-set form-buttons btn-only">
            <button type="submit" class="button"><span><span><?php echo $this->__('Submit Review') ?></span></span></button>
        </div>
        <p class="required"><?php echo $this->__('* Required Fields') ?></p>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('review-form');
    Validation.addAllThese(
    [
           ['validate-rating', '<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Please select one of each of the ratings above')) ?>', function(v) {
                var trs = $('product-review-table').select('tr');
                var inputs;
                var error = 1;

                for( var j=0; j < trs.length; j++ ) {
                    var tr = trs[j];
                    if( j > 0 ) {
                        inputs = tr.select('input');

                        for( i in inputs ) {
                            if( inputs[i].checked == true ) {
                                error = 0;
                            }
                        }

                        if( error == 1 ) {
                            return false;
                        } else {
                            error = 1;
                        }
                    }
                }
                return true;
            }]
    ]
    );
//]]>
</script>
<?php else: ?>
<div class="box-content">
    <p class="review-nologged" id="review-form">
        <?php echo $this->__('Only registered users can write reviews. Please, <a href="%s">log in</a> or <a href="%s">register</a>', $this->getLoginLink(), Mage::helper('customer')->getRegisterUrl()) ?>
    </p>
</div>
<?php endif ?>
